package com.zhai.test.infrastructure;

import com.alibaba.fastjson.JSON;
import com.zhai.infrastructure.persistent.dao.IRaffleActivityCountDao;
import com.zhai.infrastructure.persistent.dao.IRaffleActivityDao;
import com.zhai.infrastructure.persistent.dao.IRaffleActivityOrderDao;
import com.zhai.infrastructure.persistent.po.RaffleActivity;
import com.zhai.infrastructure.persistent.po.RaffleActivityCount;
import com.zhai.infrastructure.persistent.po.RaffleActivityOrder;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.RandomStringUtils;
import org.jeasy.random.EasyRandom;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @Description: 抽奖活动数据库测试类
 * @ClassName: RaffleActivityDao
 * @Author: zhaiyongxin
 * @Date: 2025/2/11 17:42
 * @Version: 1.0
 */
@Slf4j
@SpringBootTest
@RunWith(SpringRunner.class)
public class RaffleActivityTest {

    @Resource
    private IRaffleActivityDao raffleActivityDao;
    @Resource
    private IRaffleActivityCountDao raffleActivityCountDao;
    @Resource
    private IRaffleActivityOrderDao raffleActivityOrderDao;
    private final EasyRandom easyRandom = new EasyRandom();

    @Test
    public void test_queryRaffleActivityList(){
        List<RaffleActivity> raffleActivities = raffleActivityDao.queryRaffleActivityList();
        log.info("查询所有抽奖活动：{}", JSON.toJSONString(raffleActivities));
    }

    @Test
    public void test_queryRaffleActivityCountList(){
        List<RaffleActivityCount> raffleActivityCounts = raffleActivityCountDao.queryRaffleActivityCountList();
        log.info("查询所有抽奖活动数量：{}", JSON.toJSONString(raffleActivityCounts));
    }

    @Test
    public void test_queryRaffleActivityOrderList(){
        List<RaffleActivityOrder> raffleActivityOrders = raffleActivityOrderDao.queryRaffleActivityOrderList();
        log.info("查询所有抽奖活动订单：{}", JSON.toJSONString(raffleActivityOrders));
    }

    @Test
    public void test_insertRaffleActivityOrder(){
        RaffleActivityOrder raffleActivityOrder = new RaffleActivityOrder();
        // EasyRandom 可以通过指定对象类的方式，随机生成对象值。如；easyRandom.nextObject(String.class)、easyRandom.nextObject(RaffleActivityOrder.class)
        raffleActivityOrder.setUserId("zyx");
        raffleActivityOrder.setActivityId(100301L);
        raffleActivityOrder.setActivityName("测试活动");
        raffleActivityOrder.setStrategyId(100006L);
        raffleActivityOrder.setOrderId(RandomStringUtils.randomNumeric(12));
        raffleActivityOrder.setOrderTime(new Date());
        raffleActivityOrder.setState("not_used");
        raffleActivityOrderDao.insert(raffleActivityOrder);
    }

    @Test
    public void test_queryRaffleActivityOrderByUserId(){
        List<RaffleActivityOrder> raffleActivityOrders = raffleActivityOrderDao.queryRaffleActivityOrderByUserId("zyx");
        log.info("根据用户id查询抽奖订单结果，{}", JSON.toJSONString(raffleActivityOrders));
    }
}
